package graphxtest

import org.apache.spark.graphx.{Edge, Graph}
import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
  * Created by Administrator on 2018/04/03.
  */
object GrahpXTest {

  def main(args: Array[String]): Unit = {

    val conf = new SparkConf()
    .setMaster("local[*]")
    .setAppName("GraphX")


    val sc: SparkContext = new SparkContext(conf)

    val data = sc.textFile("G:\\TestData\\GraphXTestData\\GraphXTestdata.txt")
    val splitData: RDD[Array[String]] = data.map(_.split("\t"))

    //点 RDD[(Long,VD)]

    val vertex: RDD[(Long, String)] = splitData.flatMap(t => t.map(t => {
      (t.hashCode.toLong, t)
    }))
    vertex.foreach(println)
    //边RDD[Edge(ED)]=>

    val uEdge: RDD[Edge[Int]] = splitData.flatMap(t => {
      val head = t.head
      t.map(name => Edge(head.hashCode.toLong, name.hashCode.toLong, 0))
    })

    val graph = Graph(vertex,uEdge)

    graph.connectedComponents()

    //图



  sc.stop()
  }

}
